﻿
#region Usings

using PolyGameEngine.GamePieces;
using PolyGameEngine.GamePieces.Common;
using PolyGameEngine.Tools;

using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

#endregion

namespace PolyMorph.CustomGamePieces
{
    class QuickSand : SensorForceTile
    {
        public QuickSand(PhysicsGame PhysicsGame, World World, Material Material,
            Texture2D SpriteSheet, Vector2 Position, int saveLineIndex, float sinkRate)
            : base(PhysicsGame, World, Material, SpriteSheet, 1, Position, 0, 1, 1, saveLineIndex, "QuickSand", 0)
        { }

        public float sinkRate = 0;
        public float vRise = 0;

        public override void Effect()
        {
            if (GamePieceInEffect.Velocity.Y > 0)
                GamePieceInEffect.Velocity = new Vector2(GamePieceInEffect.Velocity.X, 0);

            vRise = GamePieceInEffect.Velocity.X / 100;

            if (GamePieceInEffect.material.Identifier.Equals("Wood"))
                sinkRate = 2f;
            else if (GamePieceInEffect.material.Identifier.Equals("Steel"))
                sinkRate = -4f;
            else if (GamePieceInEffect.material.Identifier.Equals("Rubber"))
                sinkRate = 2f;
            else if (GamePieceInEffect.material.Identifier.Equals("Plastic"))
                sinkRate = 4f;

            bodyInEffect.ApplyForce(new Vector2(0, -sinkRate * +vRise));


            if (GamePieceInEffect.position.Y > position.Y)
            {
                if (GamePieceInEffect.GetType().Equals(typeof(CircleUnit)))
                {
                    LevelEditor.Level.Reload();
                }
            }

        }

        public override bool HandleDefaultCollision(Fixture ThisFixture, Fixture OtherFixture, Contact Contact)
        {
            return false;
        }

    }
}